# Replication material for: Precarious work and challenger parties: how precarity influenced vote choice in the 2018 Italian election (Figure 1)
# author: Elisabetta Girardi
# date: 09/07/2023
## ----setup-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rm(list = ls())
gc()

ipak <- function(pkg) {
  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
  if (length(new.pkg)) 
    install.packages(new.pkg, dependencies = TRUE)
  sapply(pkg, require, character.only = TRUE)
}

Packages <- c("rio", "haven", "janitor", "stargazer", "foreign", "magrittr",
              "nnet", "MASS", "MNLpred", "ggplot2", "ggplot2", "extrafont", "scales", "effects", "ggpubr",
              "jtools", "DAMisc", "simEd", "readxl", "patchwork", "ggthemes")

ipak(Packages)


set.seed(260423)

## -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
setwd(" ") #Add working directory
EPL <- read_excel("OECD_DATA_Employment_protection_legislation.xlsx") #OECD data, retrieved from: https://stats.oecd.org/

Temp<-ggplot(EPL, aes(Year, Temporary))+ 
  geom_line() +
  xlab("") + 
  ylab("")+
  geom_line(size = 0.8, alpha = 0.8) +
  theme_few()+ 
  scale_x_continuous(breaks=seq(1990, 2018, 5))+
  scale_x_continuous(breaks = scales::pretty_breaks()) +
  scale_y_continuous(breaks=seq(0, 6, 1))+
  theme(text = element_text(family = "LM Roman 10"))+
  ylim(0,6)+
  geom_vline(xintercept=2012,linetype=2)+ 
  ggtitle("Temporary contracts")+
  ggeasy::easy_center_title()+ theme(text = element_text(size = 16))+
  theme(axis.text.x = element_text( size=18))+
  theme(axis.text.y = element_text( size=18))

Perm<-ggplot(EPL, aes(Year, Permanent))+ 
  geom_line() +
  xlab("") + 
  ylab("")+
  geom_line(size = 0.8, alpha = 0.8) +
  theme_few()+ 
  scale_x_continuous(breaks=seq(1990, 2018, 5))+
  scale_x_continuous(breaks = scales::pretty_breaks()) +
  scale_y_continuous(breaks=seq(0, 6, 1))+
  theme(text = element_text(family = "LM Roman 10"))+
  ylim(0,6)+
  geom_vline(xintercept=2012,linetype=2)+ 
  ggtitle("Permanent contracts")+
  ggeasy::easy_center_title()+ theme(text = element_text(size = 16))+
  theme(axis.text.x = element_text( size=18))+
  theme(axis.text.y = element_text( size=18))


png(file="EPL.png", width =10, height = 4, units = 'in', res = 1200)
Temp + Perm 
dev.off()